package com.itheima.jobs;

import com.itheima.constant.RedisConstant;
import com.itheima.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class ClearImgJob {

    @Autowired
    private JedisPool jedisPool;
    public void clearImg(){
        Set<String> sdiff = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if(sdiff!=null){
            for (String picName : sdiff) {
                //清理七牛云垃圾图片
                QiniuUtils.deleteFileFromQiniu(picName);
            }
            //将redis中的所有图片名称全部删除
            jedisPool.getResource().del(RedisConstant.SETMEAL_PIC_RESOURCES);
            jedisPool.getResource().del(RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        }

    }
}
